package javabase.schoolwork.day6_19;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;

/**
 * @author fance
 * @date 2018/6/19 21:07
 */
public class UDPClient {
    public static void main(String[] args) throws IOException {
        DatagramSocket datagramSocket = null;
        byte[] buf = new byte[1024];
        DatagramPacket datagramPacket = null;

        datagramSocket = new DatagramSocket(9000);
        datagramPacket = new DatagramPacket(buf,1024);

        datagramSocket.receive(datagramPacket);

        String s = new String(datagramPacket.getData(),0,datagramPacket.getLength());

        s += "from" + datagramPacket.getAddress().getHostAddress()+ " : " + datagramPacket.getPort();

        System.out.println(s);
        datagramSocket.close();
    }
}
